package smartbooks.ui.helper;

import smartbooks.exceptions.MyException;
import smartbooks.ui.util.CommonConstants;
import smartbooksdb.hibernatebean.Organization;

/**
 *
 * @author Ankit
 */
public class OrganizationHelper implements CommonConstants {

    /**
     * This method is used to validate the organization panel
     * @param organization
     * @return 'true' if organization panel is validated or else 'false'
     * @throws MyException
     */
    public static boolean validateOrganization(Organization organization) throws MyException {
        boolean organizationPanelValidated = true;
        
        if(null==organization.getOrgName() || organization.getOrgName().length()==0) {
            throw new MyException(ORGANIZATION_NAME, "Organization name cannot be blank");
        }
        
        if(null!=organization.getState() && organization.getState().length()>32) {
            throw new MyException(STATE, "State should have maximum 32 characters");
        }
        
        if(null!=organization.getCity() && organization.getCity().length()>32) {
            throw new MyException(CITY, "City should have maximum 32 characters");
        }
        
        return organizationPanelValidated;
    }
}
